let HtmlWebpackPlugin = require('html-webpack-plugin');
let path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
  entry: './src/main.js',
  mode: 'production',//development
  output: {//线上的时候 hash值 js 304  根据文件名字和内容生成的
    filename: "[name].js",
    path: path.join(__dirname, './dist')
  },
  devServer: {
    port: 9999,
    // quit: true,
  },
  devtool: "source-map",
  // 'source-map': true,
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              "presets": ['@babel/preset-env'],
              "plugins": ['@babel/plugin-transform-runtime']
            }
          }
        ]
      },
      {
        test: /\.css$/,
        use: [//loader加载顺序 从后往前的
          'vue-style-loader', 'style-loader', 'css-loader'
        ]
      },
      {
        test: /\.vue$/,
        use: [
          {
            loader: 'vue-loader',
            options: {
              compiler: require('vue-template-compiler'),
              transformAssetUrls: {
                video: ['src', 'poster'],
                source: 'src',
                img: 'src',
                image: ['xlink:href', 'href'],
                use: ['xlink:href', 'href']
              }
            }
          }
        ],
        include: path.join(__dirname, './src'),
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|jpeg|gif|mp3|mp4)$/,
        use: [
          {
            loader: 'file-loader',
            options: {//require()
              esModule: false
            }
          }
        ]
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js', // vue.common.js
      '@': path.join(__dirname, './src')
    }
  },
  plugins: [
    // 请确保引入这个插件！
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: './index.html'
    })
  ]
};
